# 给我写一个fast_api的例子
import json
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

app = FastAPI()
# 添加CORS中间件
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # 允许所有源
    allow_credentials=True,
    allow_methods=["*"],  # 允许所有方法
    allow_headers=["*"],  # 允许所有头
)


@app.get("/")
def read_root():
    return {"Hello": "World"}


@app.get("/userinfo")
def read_item():
    # 接受请求参数
    return {"username": "张三", "age": 25}


if __name__ == "__main__":
    uvicorn.run("fast_api:app", host="127.0.0.1", port=8080, reload=True)
